<%@page contentType="text/html; charset=utf-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<div class="pageContent" style="padding: 5px">
	<div>
		<div id="updateRoleTree"
			style="float: left; display: block; margin: 10px; overflow: auto; width: 200px; height: 500px; border: solid 1px #CCC; line-height: 21px; background: #FFF;">

			<!--此处插入updateRoleTree树 -->
		
		</div>
		<div id="jbsxBox" class="unitBox" style="margin-left: 246px;">
					<div class="pageContent">
						<form method="post" class="pageForm required-validate"
							onsubmit="return validateCallback(this,navTabAjaxDone)">
							<div class="pageFormContent nowrap" layoutH="58">
								<input type="hidden" name="updateFunctionIdsStr" id="updateFunctionIdsStr" value=""/>
								<input type="hidden" id="roleId" name="roleId" value="${role.id}" />
								<dl>
									<dt>
										<span class="tabtitle">角色状态</span>:
									</dt>
									<dd>
										<select class="combox" name="status" id="roleStatus">
											<option value="0" ${role.status == "0" ? "selected='selected'" : "" }>有效</option>
											<option value="1" ${role.status == "1" ? "selected='selected'" : "" }>冻结</option>
										</select>
									</dd>
								</dl>
								<dl>
									<dt>
										<span class="tabtitle">角色名称</span>:
									</dt>
									<dd>
										<input class="required textinput" type="text"
											value="${role.roleName}" name="roleName" size="30" id="roleName" />
									</dd>
								</dl>
								<dl>
									<dt>
										<span class="tabtitle">角色描述</span>:
									</dt>
									<dd>
										<textarea cols="28" rows="3" name="roleDesc" id="roleDesc">${role.roleDesc}测试</textarea>
									</dd>
								</dl>
								<ul>
									<li>
										<div class="buttonActive">
											<div class="buttonContent">
												<span id="menuArr" style="display: none;">${menuArr }</span> 
												<button type="button" value="修改保存" id="updateRole" class="w3" onclick="saveUpdRole()">
													保存
												</button>

											</div>
										</div>
									</li>
								</ul>
								<dl>
									<dt style=" width: 50%;">
										<span style="color:#f00; padding-top: 15px; line-height: 22px;font-size:14px;">
											&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果需要当前对角色绑定某个菜单, 勾选复选框即可; 接触绑定, 则去除勾选, 最后点击保存按钮.
										</span>
									</dt>
								</dl>
							</div>
						</form>
					</div>
				</div>
	</div>
</div>
<SCRIPT type="text/javascript">
$(document).ready(function(){
	getSysMenu();
});
function getTree(data, parentId){ 
    var tree; 
    if(parentId == 0){ 
        tree = '<ul class="tree treeCheck expand " oncheck=getFunctionIds id="updateTreelist">'; 
    }else{ 
        tree = '<ul>'; 
    } 
    
    $.each(data, function(i, ele){
    	if(data[i].parentId == parentId){ 
        	tree += "<li><a href=javascript:; tname='functionName'  tvalue='"+data[i].id+"'";
        	if(data[i].check == 1){
        		tree+=" checked=true";
        	}
        	tree +=">"+data[i].menuName+"</a>";
            tree += getTree(data, data[i].id); 
            tree += "</li>"; 
        } 
    });
    return tree+"</ul>"; 
} 

function getSysMenu(){
	var menuJson = $.parseJSON($.trim($("#menuArr").text()));
	$("#updateRoleTree").html(getTree(menuJson, 0).replaceAll("<ul></ul>",""));
}
  
function getFunctionIds(){
    $("#modifyFunctions").val("modifyFunctions");
	var json = arguments[0], result="";
	var checkedBox=$("#updateTreelist").find('[type=checkbox][checked]');
	checkedBox.each(function(i){	
		result += this.value;
		if(i<checkedBox.length-1){
			result+=";";
		}
	});
	$("#updateFunctionIdsStr").val(result);
}
function saveUpdRole(){
	var ids = $("#updateFunctionIdsStr").val();
	var roleName = $("#roleName").val();
	if($.trim(roleName)==""){
		alertMsg.error("请输入角色名称!");
		return;
	}
	$.post('updateRole', {"roleId": $("#roleId").val(), "roleName": roleName,"roleDesc": $("#roleDesc").val(), "menuIds": ids, "status": $("#roleStatus").val()}, 
		function(data) { 
			var rlt = $.parseJSON(data.result);	
			var statusCode = rlt.statusCode;
			var msg = rlt.message;
			alertMsg.info(msg);
			if(statusCode==200){
				var tabId = $("ul.navTab-tab li.selected").attr("tabid");
				navTab.reloadFlag(tabId);
			}				
	}, "json");
}
</SCRIPT>




